<?php
require_once(dirname(dirname(dirname(__FILE__))) . '/app.php');

need_manager(true);

$constellations = array(
	'1' => '水瓶座',
	'2' => '双鱼座',
	'3' => '白羊座',
	'4' => '金牛座',
	'5' => '双子座',
	'6' => '巨蟹座',
	'7' => '狮子座',
	'8' => '处女座',
	'9' => '天枰座',
	'10' => '天蝎座',
	'11' => '射手座',
	'12' => '摩羯座',
);

$degrees = array(
	'1' => '本科',
	'2' => '硕士',
	'3' => '博士',
	'4' => '其他',
);


$id = abs(intval($_GET['id']));
if (!$id || !$guest = Table::Fetch('guest', $id)) {
	redirect( WEB_ROOT . '/guest/create.php');
}

if ($_POST) {
	$insert = array(
		'user_id', 'name', 'mobile', 'email', 'title', 'summary', 'age', 'gender', 'height', 'weight', 'constellation', 'degree', 
		'career', 'resident', 'hometown', 'salary', 'hobby', 'detail', 'image', 'image1', 'image2', 'image3', 'vcr', 'judge', 
		'begin_time', 'end_time', 'now_number', 'system', 'status',
		);
	$table = new Table('guest', $_POST);
	$table->SetStrip('detail', 'judge', 'summary');
	$table->begin_time = strtotime($_POST['begin_time']);
//	$table->city_id = abs(intval($table->city_id));
	$table->end_time = strtotime($_POST['end_time']);
//	$table->expire_time = strtotime($_POST['expire_time']);
//	$table->now_number = abs(intval($table->now_number));
	$table->image = upload_image('image', $guest['image'], 'guest');
	$table->image1 = upload_image('image1',$guest['image1'],'guest');
	$table->image2 = upload_image('image2',$guest['image2'],'guest');

	$error_tip = array();
	if ( !$error_tip)  {
		if ( $table->update($insert) ) {

//			$field = strtoupper($table->conduser)=='Y' ? null : 'quantity';
/*
			$now_number = Table::Count('order', array(
						'guest_id' => $table->id,
						'state' => 'pay',
						), $field);

			Table::UpdateCache('guest', $table->id, array(
				'now_number' => ($table->now_number + $now_number),
			));
*/
			Session::Set('notice', '修改团信息成功');
			redirect( WEB_ROOT. "/manage/guest/edit.php?id={$guest['id']}");
		} else {
			Session::Set('error', '修改团信息失败，请检查系统环境？');
		}
	}
}
/*
$groups = DB::LimitQuery('category', array(
			'condition' => array( 'zone' => 'group', ),
			));
$groups = Utility::OptionArray($groups, 'id', 'name');

$partners = DB::LimitQuery('partner', array(
			'order' => 'ORDER BY id DESC',
			));
$partners = Utility::OptionArray($partners, 'id', 'title');
*/

include template('manage_guest_edit');
